package com.cuitrip.business.order.ui;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.cuitrip.business.order.detail.OrderFormActivity;
import com.cuitrip.business.order.model.ConversationOrderItem;
import com.cuitrip.business.order.model.OrderItem;
import com.cuitrip.service.R;
import com.cuitrip.util.time.InputTime;
import com.cuitrip.util.time.OutputTime;
import com.cuitrip.util.time.TimeUtil;
import com.lab.adapter.BaseHolderView;
import com.lab.adapter.IAdapterData;
import com.lab.utils.ImageHelper;

import butterknife.Bind;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ak on 15/10/15.
 */
public class InsiderOrderConversationHolderView extends BaseHolderView {

    @Bind(R.id.order_date)
    TextView order_date;
    @Bind(R.id.ct_message_img)
    CircleImageView ctMessageImg;
    @Bind(R.id.author_img)
    CircleImageView authorImg;
    @Bind(R.id.author_name)
    TextView authorName;
    @Bind(R.id.service_name)
    TextView serviceName;
    @Bind(R.id.order_status)
    TextView orderStatus;


    public InsiderOrderConversationHolderView(Context context) {
        super(context, R.layout.conversations_insider_order);
    }


    @Override
    public void initView(View rootView) {
        this.setClickable(true);
        ButterKnife.bind(this);
    }

    @Override
    public void bindData(IAdapterData data, int position) {
        if (data instanceof ConversationOrderItem) {
            final ConversationOrderItem item = (ConversationOrderItem) data;
            ImageHelper.displayPersonImage(item.getHeadPic(), authorImg, null);
            authorName.setText(item.getUserNick());
            Context context=order_date.getContext();
            String formatCommonTime = TimeUtil.formatTime(InputTime.build(item.getServiceDate(), TimeUtil.getZeroZone()), OutputTime.getInstance(OutputTime.OutputType.Type_DAY, TimeUtil.getZeroZone()));
            order_date.setText(context.getString(R.string.book_trip_date, formatCommonTime));

            serviceName.setText(item.getServiceName());
            ctMessageImg.setVisibility(item.getUnreadCount() > 0 ? View.VISIBLE : View.GONE);
            orderStatus.setText(item.getStatusContent());
            switch (item.getStatus()){
                case OrderItem.STATUS_WAIT_CONFIRM:
                    orderStatus.setTextColor(getResources().getColor(R.color.sky_blue_00d4ff));
                    break;
                default:
                    orderStatus.setTextColor(getResources().getColor(R.color.ct_black));
                    break;
            }
            setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (item.getUnreadCount() > 0) {
                        OrderFormActivity.startConversation(getContext(), item.getOid());
                    } else {
                        OrderFormActivity.start(getContext(), item.getOid());
                    }

                }
            });
        }
    }
}
